local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name);
local LikeGame_Cfg=ClientOHOH.config.LikeGame;
local CallBackManager = ClientOHOH.load.CallBackManager();
local Reward=LikeGame_Cfg.Reward;
local FunctionList = ClientOHOH.load.FunctionList();
FunctionList.receive_reward=true;
local GlobalTipGui = ClientOHOH.load.UIManager().ui_list.GlobalTipGui;
local LanguageHelper= _G.LanguageHelper;
local ItemTool=_G.CommonOHOH.load.ItemTool();
local CommonOHOH = _G.CommonOHOH;
local BigNumberHelper = CommonOHOH.load.BigNumberHelper();
local Client_AudioManager = ClientOHOH.load.Client_AudioManager();
function M.new(self,...)
	return M(self,...);
end;
function M.ctor(self, parent)
	M.super.ctor(self, parent);
    --玩家领奖到的阶段
    self.dataBase=self.parent:GetComponent(ClientOHOH.load.Client_PlayerDataComponent());
    self.data = self.dataBase:GetData("likeGame");
    self.Level=self.dataBase:GetData("base").level;
    self:Init();
    self:SetLikeGameCountView();--显示当前目标奖励
    self:ReceiveReward();--绑定点击事件
    self.parent.UserDataEvent:Connect(function(data)
        if data["base"] and data["base"].level~=self.Level then
            self.Level=data["base"].level;
            self:SetLikeGameCountView();
        end;
        if(data["likeGame"])then
            self.data = self.dataBase:GetData("likeGame");
            self:SetLikeGameCountView();
            self:ShowLikeGameReward();
            self:ReceiveReward();
        end
    end);
end;
function M.Init(self)
    local LikeGameModel=ClientOHOH:GetPath_Loop("LikeGame",game.Workspace);
    -- LikeGameModel.Parent=workspace;
    self.likeGameTxt=ClientOHOH:GetPath_Loop("ui.SurfaceGui.TextLabel",LikeGameModel);
    self.itemIcon=ClientOHOH:GetPath_Loop("ui.SurfaceGui.back.icon",LikeGameModel);
    self.itemCount=ClientOHOH:GetPath_Loop("ui.SurfaceGui.back.TextLabel",LikeGameModel);
    self.receiveBtn=ClientOHOH:GetPath_Loop("ui.SurfaceGui.btn",LikeGameModel);

    self.likeGameTitle=ClientOHOH:GetPath_Loop("ui.SurfaceGui.like",LikeGameModel);
    self.receiveBtnText=ClientOHOH:GetPath_Loop("TextLabel",self.receiveBtn);
    self.likeGameTitle.Text=LanguageHelper:GetText(530004);
    self.receiveBtnText.Text=LanguageHelper:GetText(530006);
    
end
function M.SetLikeGameCountView(self)
    local targetIndex=self.data.receiveCount+1;
    self.likeGameTxt.Text=LanguageHelper:GetText(530005,{"%%ARG1"},{Reward[targetIndex].like_count});
    local image=_G.CommonOHOH.load.ItemTool().GetItemShowView(Reward[targetIndex].item_id)
    self.itemIcon.Image=image

    local itemId,count=ItemTool.GetRewardByLevel(Reward[targetIndex].item_id,Reward[targetIndex].count,self.Level);
    local p=math.floor(count);
    self.itemCount.Text="x" ..BigNumberHelper:ToString(p);
    
end;
function M.ReceiveReward(self)
    self.ClickConnect=CallBackManager:AddRbxConnect(self, self.receiveBtn.Activated, function()
        if self.ClickConnect then
            self.ClickConnect:Disconnect()
            self.ClickConnect=nil
        end
        local isReceive= self.parent:Invoke(FunctionList.receive_reward,self.data.receiveCount);
        if(not isReceive) then
            GlobalTipGui:Show(LanguageHelper:GetText(530003));
            self:ReceiveReward();    
        end
    end);
end
function M.ShowLikeGameReward(self)
	local item_id,count=ItemTool.GetRewardByLevel(LikeGame_Cfg.Reward[self.data.receiveCount].item_id,LikeGame_Cfg.Reward[self.data.receiveCount].count,self.Level);
    ItemTool.FlyingItem(item_id,count)
    Client_AudioManager:PlayGloble("claim");
end
function M.dtor(self)
	M.super.dtor(self);
end;
return M;